<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>喜好调查</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<link rel="stylesheet" type="text/css" href="css/index.css"/>
	</head>
	<body class="bg_ff">
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title text_left">喜好调查</h1>
		    <a href="index.html" class="jump mg_top10 right color_9">跳过</a>
		</header>
		<div class="mui-content bg_ff padding_12">
		    <div class=" color_55 mg_top10">回答问题可以获取积分哦</div>
		   
		    <div class=" mg_top20" id="like_box">
		    	 <div class="color_55 bold mg_top10 title "></div>
		    	 <div class="like_box">
			    	
			    		
			    	
		    	 </div>
		    </div>
		    <p class="mg_top40 width90"><a href="javascript:void(0)" class="big_btn refire" onclick="likeBtn()">提交</a></p>
		    <p class="mg_top40 width90"><a href="javascript:void(0)" class="big_btn next" onclick="like(page)">下一步</a></p>
		    
		</div>
		
		
		
	
		
		
		<script src="js/mui.js"></script>
		<script src="js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init()
			var isAnswer = localStorage.getItem('isAnswer')
			if(isAnswer==2){
				window.location.href = 'index.html'
			}
			
			//获取喜好列表
			$('.refire').hide()
			var page =0
			page++
			function like(page){
				console.log(page)
				$.ajax({
					type:"get",
					url:urlcom + "user/getSurveyList",
					async:true,
					dataType:'json',
					success:function(res){
						if(res.code==0){
							var html='';
							console.log(page)
							if(res.data.length==1){
								$.each(res.data, function(k,v) {
									$('.refire').show();
									$('.next').hide();
										html+='<div class="color_55 bold mg_top10 title " id='+v.surveyId+'>'+(k+1)+'. '+ v.title+'</div>'+
										'<div class="like_box mg_top20">'
										$.each(v.options, function(m,n) {
												
												html+='<div class="like_list">'+
											    	'<div class="mui-input-row mui-radio ">'
											        if(v.type==1){
											    	    html+='<label><img src="'+n+'"/></label>'
											        }else if(v.type==2){
											        	  html+='<label>'+n+'</label>'
											        }
											    	  html+='<input name="radio" type="radio" value="'+m+'" >'+
											    	'</div>'+
										    	'</div>'
											
										});
										html+='</div>'
									
								});
							}else if(res.data.length>1){
								
							    $.each(res.data, function(k,v) {
								if(k==page){
									// $('.big_btn').text('提交')
									// 
									if(k==1){
										$('.refire').show();
										$('.next').hide();
									}
									html+='<div class="color_55 bold mg_top10 title " id='+v.surveyId+'>'+(k+1)+'. '+ v.title+'</div>'+
									'<div class="like_box mg_top20">'
									$.each(v.options, function(m,n) {
											
											html+='<div class="like_list">'+
										    	'<div class="mui-input-row mui-radio ">'
										        if(v.type==1){
										    	    html+='<label><img src="'+n+'"/></label>'
										        }else if(v.type==2){
										        	  html+='<label>'+n+'</label>'
										        }
										    	  html+='<input name="radio" type="radio" value="'+m+'" >'+
										    	'</div>'+
									    	'</div>'
										
									});
									html+='</div>'
								}
							});
							}
							page++
							$('#like_box').html(html)
						}
					}
				});
			}like(0)
		    
			
			   
            //提交喜好
			function likeBtn(){
				var answer = $('input[type=radio]:checked').val()
			
				console.log(answer)
				if(answer==0){
					answer = 'a'
				}else if(answer == 1){
					answer='b'
				}else if(answer == 2){
					answer='c'
				}else if(answer == 3){
					answer='d'
				}
				$('.gif').show()
				$.ajax({
					type:"POST",
					url:urlcom + "user/surveySubmit",
					async:true,
					dataType:'json',
					data:{
						userId:localStorage.getItem('userId'),
						surveyId:$('.title').attr('id'),
						answer:answer
					},
					success:function(res){
					$('.gif').hide()
						if(res.code==0){
							msg('提交成功')
							setTimeout(function(){
								window.location.href='index.html'
							},1500)
							
						}
					}
			})
		}		
		</script>
	</body>

</html>
